|
Radar Host Communication library
2020.08.13
|
This file implements the access Infineon sensor devices. More...
#include "Protocol.h"#include "Protocol_internal.h"#include "COMPort.h"#include <stddef.h>#include <stdlib.h>#include <string.h>#include "Protocol_KnownEndpoints.h"Go to the source code of this file.
Macros | |
| #define | _CRT_SECURE_NO_WARNINGS |
| #define | CNST_STARTBYTE_DATA 0x5A |
| #define | CNST_STARTBYTE_STATUS 0x5B |
| #define | CNST_END_OF_PAYLOAD 0xE0DB |
| #define | CNST_MSG_QUERY_ENDPOINT_INFO 0x00 |
| #define | CNST_MSG_ENDPOINT_INFO 0x00 |
| #define | CNST_MSG_QUERY_FW_INFO 0x01 |
| #define | CNST_MSG_FW_INFO 0x01 |
| #define | CNST_MSG_FIRMWARE_RESET 0x02 |
| #define | CNST_PROTOCOL_RECEIVED_PAYLOAD_MSG 0x01000000 |
| #define | NUM_KNOWN_ENDPOINTS (sizeof(known_endpoints) / sizeof(const Endpoint_Definition_t*)) |
Functions | |
| Port_Info_t | parse_port_name (const char *port_name) |
| int32_t | protocol_connect (const char *port_name) |
| This function establishes a connection to a device through a COM port. More... | |
| void | protocol_disconnect (int32_t protocol_handle) |
| This function closes an open connection. More... | |
| int32_t | protocol_get_num_endpoints (int32_t protocol_handle) |
| This function returns the number of endpoints in the connected device. More... | |
| int32_t | protocol_get_firmware_information (int32_t protocol_handle, Firmware_Information_t *information) |
| This function returns the information about the firmware of the connected device. More... | |
| int32_t | protocol_do_firmware_reset (int32_t protocol_handle) |
| This function triggers a firmware reset of the connected device. More... | |
| int32_t | protocol_get_endpoint_info (int32_t protocol_handle, uint8_t endpoint, Endpoint_Info_t *endpoint_info) |
| This function returns information about the requested endpoint. More... | |
| int32_t | protocol_is_endpoint_compatible (int32_t protocol_handle, uint8_t endpoint, const Endpoint_Definition_t *endpoint_definiton) |
| int32_t | protocol_send_and_receive (int32_t protocol_handle, uint8_t endpoint, const Endpoint_Definition_t *endpoint_definiton, const uint8_t *payload, uint16_t payload_size) |
| const char * | protocol_get_status_code_description (int32_t protocol_handle, int32_t status_code) |
| This function returns a human readable description of a status or error code. More... | |
| int32_t | protocol_poll_receive_once (int32_t protocol_handle) |
This file implements the access Infineon sensor devices.
The API to this module is split up into the two header files Protocol.h and Protocol_internal.h. See Protocol.h for a basic description of the communication scheme. That header declares functions to be called by users of the communication library. The header Protocol_internal.h declares those functions that are meant to be called by endpoint implementations inside the communication library.
Definition in file Protocol.c.
| #define _CRT_SECURE_NO_WARNINGS |
Definition at line 31 of file Protocol.c.
| #define CNST_END_OF_PAYLOAD 0xE0DB |
Every payload message ends with this 16 bit value (transmitted with low byte first!).
Definition at line 67 of file Protocol.c.
| #define CNST_MSG_ENDPOINT_INFO 0x00 |
A message containing endpoint information sent from endpoint 0 starts with this message type code.
Definition at line 82 of file Protocol.c.
| #define CNST_MSG_FIRMWARE_RESET 0x02 |
This command code sent to endpoint 0 tells the device to do a firmware reset.
Definition at line 103 of file Protocol.c.
| #define CNST_MSG_FW_INFO 0x01 |
A message containing firmware information sent from endpoint 0 starts with this message type code.
Definition at line 96 of file Protocol.c.
| #define CNST_MSG_QUERY_ENDPOINT_INFO 0x00 |
This command code sent to endpoint 0 tells the device to send information about the protocol endpoints.
Definition at line 75 of file Protocol.c.
| #define CNST_MSG_QUERY_FW_INFO 0x01 |
This command code sent to endpoint 0 tells the device to send information about its firmware.
Definition at line 89 of file Protocol.c.
| #define CNST_PROTOCOL_RECEIVED_PAYLOAD_MSG 0x01000000 |
If get_message received a regular payload message, this code is returned.
Definition at line 109 of file Protocol.c.
| #define CNST_STARTBYTE_DATA 0x5A |
A payload message begins with this code byte.
Definition at line 61 of file Protocol.c.
| #define CNST_STARTBYTE_STATUS 0x5B |
A status message begins with this code byte.
Definition at line 64 of file Protocol.c.
| #define NUM_KNOWN_ENDPOINTS (sizeof(known_endpoints) / sizeof(const Endpoint_Definition_t*)) |
Definition at line 254 of file Protocol.c.
| Port_Info_t parse_port_name | ( | const char * | port_name | ) |
Definition at line 524 of file Protocol.c.
| int32_t protocol_connect | ( | const char * | port_name | ) |
This function establishes a connection to a device through a COM port.
This function tries to open the specified COM port. The COM port name must identify an existing COM port and is platform and machine specific. It is recommended to call com_get_port_list to get a list of available COM ports. Port names not in the returned list won't be accepted.
If the specified COM could be opened, information about the endpoints present in the connected device is queried. If endpoint information could not be retrieved properly, the device is considered to not be compatible with the communication protocol and the connection is closed again.
If a connection can be established, the function returns a handle that must be passed to all following function calls to identify the device. When the connection is not needed any more, it should be closed by calling protocol_disconnect.
| [in] | port_name | A zero-terminated string containing the device name of the COM port to use or the address of an UDP server in the form udp://server:port. |
Definition at line 573 of file Protocol.c.
| void protocol_disconnect | ( | int32_t | protocol_handle | ) |
This function closes an open connection.
If a valid handle to an open connection is provided, the according connection is closed and the handle is marked as invalid. If the handle is invalid, nothing will happen. Either way the handle must not be used any more after calling this function.
| [in] | protocol_handle | A handle to an open connection. |
Definition at line 723 of file Protocol.c.
| int32_t protocol_do_firmware_reset | ( | int32_t | protocol_handle | ) |
This function triggers a firmware reset of the connected device.
This function sends a message to the connected device to trigger a firmware ware reset and waits for the answer.
After calling this function, protocol_disconnect should be called immediately to ensure a proper reboot of the connected device.
| [in] | protocol_handle | A handle to an open connection returned. |
Definition at line 846 of file Protocol.c.
| int32_t protocol_get_endpoint_info | ( | int32_t | protocol_handle, |
| uint8_t | endpoint, | ||
| Endpoint_Info_t * | endpoint_info | ||
| ) |
This function returns information about the requested endpoint.
When the connection is established (see protocol_connect), information about the endpoints in the connected device is retrieved. This function returns information about the requested endpoints that was received when the connection was established. The endpoint information is not queried from the device again.
The caller must provide a valid pointer to a structure of type Endpoint_Info_t. That structure may be uninitialized.
| [in] | protocol_handle | A handle to an open connection. |
| [in] | endpoint | The number of the requested endpoint. (First endpoint is 1, not 0!) |
| [out] | endpoint_info | A pointer to the structure, where the endpoint information will be written to. |
Definition at line 890 of file Protocol.c.
| int32_t protocol_get_firmware_information | ( | int32_t | protocol_handle, |
| Firmware_Information_t * | information | ||
| ) |
This function returns the information about the firmware of the connected device.
This function sends a message to the connected device to query information about the firmware and waits for the answer. The reply message is evaluated and firmware information is written into the provided structure.
Note: This function allocates memory to hold the firmware description string. The caller must take core for freeing that memory when it's no longer needed.
| [in] | protocol_handle | A handle to an open connection returned. |
| [out] | information | A pointer to the structure, where the firmware information will be stored. |
Definition at line 768 of file Protocol.c.
| int32_t protocol_get_num_endpoints | ( | int32_t | protocol_handle | ) |
This function returns the number of endpoints in the connected device.
When the connection is established (see protocol_connect), information about the endpoints in the connected device is retrieved. A device compatible with the communication protocol contains at least one endpoint. If a board reports to have no endpoints, the connection won't be established. This function returns the number of endpoints received when the connection was established. The number of endpoints is not queried from the device again.
| [in] | protocol_handle | A handle to an open connection returned. |
Definition at line 755 of file Protocol.c.
| const char* protocol_get_status_code_description | ( | int32_t | protocol_handle, |
| int32_t | status_code | ||
| ) |
This function returns a human readable description of a status or error code.
Whenever a protocol or endpoint function returns a negative error code or a positive status code sent by an endpoint in a connected device, this function can be used to get a human readable description of that code.
The protocol handle is needed when retrieving a description for a status code sent by the device. When retrieving the description of a negative error code, the handle is ignored. This allows to retrieve error description in case a connection could not be established.
| [in] | protocol_handle | A handle to an open connection. |
| [in] | status_code | The status or error code to be described. |
Definition at line 1023 of file Protocol.c.
| int32_t protocol_is_endpoint_compatible | ( | int32_t | protocol_handle, |
| uint8_t | endpoint, | ||
| const Endpoint_Definition_t * | endpoint_definiton | ||
| ) |
Definition at line 927 of file Protocol.c.
| int32_t protocol_poll_receive_once | ( | int32_t | protocol_handle | ) |
Definition at line 1151 of file Protocol.c.
| int32_t protocol_send_and_receive | ( | int32_t | protocol_handle, |
| uint8_t | endpoint, | ||
| const Endpoint_Definition_t * | endpoint_definiton, | ||
| const uint8_t * | payload, | ||
| uint16_t | payload_size | ||
| ) |
Definition at line 957 of file Protocol.c.